package com.yanjue.fallback;

import com.yanjue.client.LikeSeeClient;
import com.yanjue.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class LikeSeeFallback implements FallbackFactory<LikeSeeClient> {
    private static final Logger LOGGER = LoggerFactory.getLogger(LikeSeeFallback.class);
    @Override
    public LikeSeeClient create(Throwable cause) {
        //发生异常，降级
        return bookId ->{
            LOGGER.error("获取喜欢看[{}]数量失败：{}", bookId, cause.getMessage());
            return ResultUtil.success(0);
        };
    }
}
